<template>
  <div class="shop-view">
    <div class="wrap">
      <div class="section-title">
        <div class="separator" />
        <div class="title">选择城市预约</div>
        <div class="separator" />
      </div>
      <city-list :list="options.city_data" @select="choiceCityConfirm" />
    </div>
    <shop-fixed
      :view="view"
      :fixed-views="fixedViews"
      @click="openChoiceCity"
    />
    <choice-city
      title="选择城市预约"
      :list="options.city_data"
      ref="choiceCity"
      @confirm="choiceCityConfirm"
    />
    <fill-in-form ref="form" @submit="submit" />
  </div>
</template>
<script>
import CityList from "../city-list";
import ChoiceCity from "../choice-city";
import formMixin from "../../../mixins";
import FillInForm from "../form/shop.vue";
import ShopFixed from "../shop-fixed";
export default {
  name: "shop-view",
  mixins: [formMixin],
  components: {
    CityList,
    ChoiceCity,
    FillInForm,
    ShopFixed,
  },
  props: {
    view: {
      type: Object,
      default: () => ({}),
    },
    fixedViews: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      activeCity: "",
    };
  },
  computed: {
    options() {
      return this.view.options || {};
    },
    directPay() {
      return this.options.form_pay == 2;
    },
  },
  methods: {
    openChoiceCity() {
      this.activeCity = "";
      if (this.directPay) {
        this.submit();
        return;
      }
      this.$refs.choiceCity.open();
    },
    choiceCityConfirm(v) {
      this.activeCity = v;
      if (this.directPay) {
        this.submit();
        return;
      }
      this.$refs.form.open();
    },
    async submit(data = {}) {
      const { query } = this.$route;
      const { biz_id, id: view_id } = this.tpl;
      const { is_payment, form_pay, pay_money } = this.options;
      let form = {
        tg_id: query.id,
        tg_type: query.type,
        order_sn: this.order_sn,
        mini_id: query.mini_id || '',
        biz_id,
        view_id,
        is_payment,
        form_type: 1,
        form_pay,
        pay_money,
        mould_type: this.view.type,
        ...data,
        // user_id
      };
      console.log(query.mini_id);
      let data_set = {
        ...(data.data_set || {}),
        city: this.activeCity,
      };
      form.data_set = JSON.stringify(data_set);
      this.$emit("submit");
      await this.adSubmit(form, "ads", this.view);
      this.$refs.form.close();
    },
  },
};
</script>
<style lang="scss" scoped>
.shop-view {
  margin: 0.26666rem;
  .wrap {
    padding: 0.48888rem 0.22222rem;
    background: #fff;
    border-radius: 6px;
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
}
.section-title {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.2rem;
  .title {
    margin: 0 0.1777777rem;
    font-size: 0.44444rem;
    font-weight: bold;
  }
  .separator {
    width: 0.888888rem;
    height: 1px;
    background: #000;
    transform: scaleY(0.5);
  }
}
</style>
